﻿using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WPRD.Models;
using WPRD.Views;

namespace WPRD
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        #region Creator
        public MainWindow()
        {
            InitializeComponent();

            //注册MVVMLight消息
            Messenger.Default.Register<string>(this, "OpenDirectory", OpenDirectory);
            Messenger.Default.Register<string>(this, "OpenFile", OpenFile);
            Messenger.Default.Register<SystemConfig>(this, "OpenSystemConfigView", OpenSystemConfigView);
            Messenger.Default.Register<List<RadarSite>>(this, "OpenRadarSiteConfigView", OpenRadarSiteConfigView);
            Messenger.Default.Register<object>(this, "Exit", Exit);

            //当前元素移除时卸载MVVMLight消息
            this.Unloaded += (sender, e) => Messenger.Default.Unregister(this);
        }
        #endregion

        #region Message Handler
        /// <summary>
        /// 打开目录
        /// </summary>
        /// <param name="directory">目录</param>
        private void OpenDirectory(string directory)
        {
            Process.Start("explorer.exe", directory);
        }

        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="path">文件路径</param>
        private void OpenFile(string path)
        {
            System.Diagnostics.Process.Start(path);
        }

        /// <summary>
        /// 打开系统配置视图
        /// </summary>
        /// <param name="systemConfig">系统配置</param>
        private void OpenSystemConfigView(SystemConfig systemConfig)
        {
            SystemConfigView systemConfigView = new SystemConfigView();
            //传递系统配置
            Messenger.Default.Send<SystemConfig>(systemConfig, "SetSystemConfig");
            systemConfigView.Owner = this;
            systemConfigView.ShowDialog();
        }

        /// <summary>
        /// 打开台站配置视图
        /// </summary>
        /// <param name="radarSiteList">台站配置</param>
        private void OpenRadarSiteConfigView(List<RadarSite> radarSiteList)
        {
            RadarSiteConfigView radarSiteConfigView = new RadarSiteConfigView();
            //传递台站配置
            Messenger.Default.Send<List<RadarSite>>(radarSiteList, "SetRadarSiteConfig");
            radarSiteConfigView.Owner = this;
            radarSiteConfigView.ShowDialog();
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="obj"></param>
        private void Exit(object obj)
        {
            this.Close();
        }
        #endregion
    }
}
